<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: Object Detection using CNNs</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../d3/d81/tutorial_contrib_root.html">Tutorials for contrib modules</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Object Detection using CNNs </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1>Building</h1>
<p>Build samples of "dnn_objectect" module. Refer to OpenCV build tutorials for details. Enable <code>BUILD_EXAMPLES=ON</code> CMake option and build these targets (Linux):</p><ul>
<li>example_dnn_objdetect_image_classification</li>
<li>example_dnn_objdetect_obj_detect</li>
</ul>
<p>Download the weights file and model definition file from <code>opencv_extra/dnn_objdetect</code></p>
<h1>Object Detection</h1>
<div class="fragment"><div class="line">example_dnn_objdetect_obj_detect  &lt;model-definition-file&gt;  &lt;model-weights-file&gt;  &lt;test-image&gt;</div></div><!-- fragment --><p>All the following examples were run on a laptop with <code>Intel(R) Core(TM)2 i3-4005U CPU @ 1.70GHz</code> (without GPU).</p>
<p>The model is incredibly fast taking just <code>0.172091</code> seconds on an average to predict multiple bounding boxes.</p>
<div class="fragment"><div class="line">&lt;bin_path&gt;/example_dnn_objdetect_obj_detect  SqueezeDet_deploy.prototxt  SqueezeDet.caffemodel  tutorials/images/aeroplane.jpg</div><div class="line"></div><div class="line">Total objects detected: 1 in 0.168792 seconds</div><div class="line">------</div><div class="line">Class: aeroplane</div><div class="line">Probability: 0.845181</div><div class="line">Co-ordinates: 41 116 415 254</div><div class="line">------</div></div><!-- fragment --><div class="image">
<img src="../../aero_det.jpg" alt="aero_det.jpg"/>
<div class="caption">
Train_Dets</div></div>
<div class="fragment"><div class="line">&lt;bin_path&gt;/example_dnn_objdetect_obj_detect  SqueezeDet_deploy.prototxt  SqueezeDet.caffemodel  tutorials/images/bus.jpg</div><div class="line"></div><div class="line">Total objects detected: 1 in 0.201276 seconds</div><div class="line">------</div><div class="line">Class: bus</div><div class="line">Probability: 0.701829</div><div class="line">Co-ordinates: 0 32 415 244</div><div class="line">------</div></div><!-- fragment --><div class="image">
<img src="../../bus_det.jpg" alt="bus_det.jpg"/>
<div class="caption">
Train_Dets</div></div>
 <div class="fragment"><div class="line">&lt;bin_path&gt;/example_dnn_objdetect_obj_detect  SqueezeDet_deploy.prototxt  SqueezeDet.caffemodel  tutorials/images/cat.jpg</div><div class="line"></div><div class="line">Total objects detected: 1 in 0.190335 seconds</div><div class="line">------</div><div class="line">Class: cat</div><div class="line">Probability: 0.703465</div><div class="line">Co-ordinates: 34 0 381 282</div><div class="line">------</div></div><!-- fragment --><div class="image">
<img src="../../cat_det.jpg" alt="cat_det.jpg"/>
<div class="caption">
Train_Dets</div></div>
 <div class="fragment"><div class="line">&lt;bin_path&gt;/example_dnn_objdetect_obj_detect  SqueezeDet_deploy.prototxt  SqueezeDet.caffemodel  tutorials/images/persons_mutli.jpg</div><div class="line"></div><div class="line">Total objects detected: 2 in 0.169152 seconds</div><div class="line">------</div><div class="line">Class: person</div><div class="line">Probability: 0.737349</div><div class="line">Co-ordinates: 160 67 313 363</div><div class="line">------</div><div class="line">Class: person</div><div class="line">Probability: 0.720328</div><div class="line">Co-ordinates: 187 198 222 323</div><div class="line">------</div></div><!-- fragment --><div class="image">
<img src="../../person_multi_det.jpg" alt="person_multi_det.jpg"/>
<div class="caption">
Train_Dets</div></div>
<p> Go ahead and run the model with other images !</p>
<h2>Changing threshold</h2>
<p>By default this model thresholds the detections at confidence of <code>0.53</code>. While filtering there are number of bounding boxes which are predicted, you can manually control what gets thresholded by passing the value of optional arguement <code>threshold</code> like:</p>
<div class="fragment"><div class="line">&lt;bin_path&gt;/example_dnn_objdetect_obj_detect  &lt;model-definition-file&gt;  &lt;model-weights-file&gt;  &lt;test-image&gt; &lt;threshold&gt;</div></div><!-- fragment --><p>Changing the threshold to say <code>0.0</code>, produces the following:</p>
<div class="image">
<img src="../../aero_thresh_det.jpg" alt="aero_thresh_det.jpg"/>
<div class="caption">
Train_Dets</div></div>
<p> That doesn't seem to be that helpful !</p>
<h1>Image Classification</h1>
<div class="fragment"><div class="line">example_dnn_objdetect_image_classification  &lt;model-definition-file&gt;  &lt;model-weights-file&gt;  &lt;test-image&gt;</div></div><!-- fragment --><p>The size of the model being <b>4.9MB</b>, just takes a time of <b>0.136401</b> seconds to classify the image.</p>
<p>Running the model on examples produces the following results:</p>
<div class="fragment"><div class="line">&lt;bin_path&gt;/example_dnn_objdetect_image_classification  SqueezeNet_deploy.prototxt  SqueezeNet.caffemodel  tutorials/images/aeroplane.jpg</div><div class="line">Best class Index: 404</div><div class="line">Time taken: 0.137722</div><div class="line">Probability: 77.1757</div></div><!-- fragment --><p>Looking at <a href="https://raw.githubusercontent.com/opencv/opencv/3.4.0/samples/data/dnn/synset_words.txt">synset_words.txt</a>, the predicted class belongs to <code>airliner</code></p>
<div class="fragment"><div class="line">&lt;bin_path&gt;/example_dnn_objdetect_image_classification  SqueezeNet_deploy.prototxt  SqueezeNet.caffemodel  tutorials/images/cat.jpg</div><div class="line">Best class Index: 285</div><div class="line">Time taken: 0.136401</div><div class="line">Probability: 40.7111</div></div><!-- fragment --><p>This belongs to the class: <code>Egyptian cat</code></p>
<div class="fragment"><div class="line">&lt;bin_path&gt;/example_dnn_objdetect_image_classification  SqueezeNet_deploy.prototxt  SqueezeNet.caffemodel  tutorials/images/space_shuttle.jpg</div><div class="line">Best class Index: 812</div><div class="line">Time taken: 0.137792</div><div class="line">Probability: 15.8467</div></div><!-- fragment --><p>This belongs to the class: <code>space shuttle</code> </p>
</div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:38 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
